package parts_of_sentence;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;

public class Text {
	public static final Logger LOG = Logger.getLogger(Text.class);
	private String text;
	private List<Sentence> listSentences = new ArrayList<Sentence>();

	public Text(String text) {
		this.text = text;
		fillListSentences();
	}

	private void fillListSentences() {
		String R = "([A-Z].+?[.!?])";
		Pattern p = Pattern.compile(R);
		Matcher m = p.matcher(text);
		while (m.find()) {
			listSentences.add(new Sentence(m.group()));
			LOG.info("added sentence");
		}
	}
	
	public void deleteWordsByLength(int lenth) {
		for (Sentence s : listSentences) {
			s.deleteWordByLength(lenth);
		}
	}

	public String collectText() {
		String collectedText = "";
		for (Sentence s : listSentences) {
			collectedText = collectedText + s.collectSentence() + "\r\n ";
		}

		return collectedText;

	}
	
	public List<Sentence> getListSentences() {
		List<Sentence> listCopy = new ArrayList<Sentence>();
		listCopy = listSentences;
		return listCopy;
	}

	@Override
	public String toString() {
		String s="";
		for (Sentence ss : listSentences){
			s=s+ss.getSentence() +"\r\n";
		}
		return s;
	}
	

}
